<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Api\Service;

class ImageScoreService{
	
    /**
     * 保存图片和谱单的关系
     * @return unknown
     */
    public function save($param){
        $model = M('ImageScore');
        $map = array(
            'score_id' => $param['score_id'],
            'is_cover' => 1
        );
        $res = $model->where($map)->find();
        if (!empty($res)) {
            //1.取消旧首图
            $data = array(
                'is_cover' => 0,
                'is_delete' => 1
            );
            $cover = $model->where($map)->save($data);
        }

        //2.创建记录
        $param['creator'] = $param['uid'];
        $param['is_cover'] = 1;
        $id = $model->add($param);

        return $id;
	}
	
	
}